<template>
    <div>
        <div class="singer-img">
            <img src="../assets/img/live.webp" alt=""><br>
            <van-icon name="checked" color="lightblue"/>
            <p>我的收藏</p>
            <div></div>
        </div>
        <div>
            <ul class="mysong">
                <li v-for="(item,index) in coll" :key="index" @click="changeUrl(item.song_id)">
                    <div class="mysong-img">
                        <img :src="item.pic_small" alt="">
                        <div>
                            <span>{{item.title}}</span><br>
                            <span>{{item.author}}</span>
                        </div>
                    </div>

                </li>
            </ul>
        </div>
    </div>
</template>

<script>
    import {getSongDetail} from "../api/api";

    export default {
        name: "collectList",
        data() {
            return {
                collectList: [],
                coll: []
            }
        },
        created() {
            this.collectList = JSON.parse(localStorage.getItem('coll')) || [];
            console.log(this.collectList);
            for (const item of this.collectList) {
                getSongDetail(item).then(res => {
                    console.log(res)
                    this.coll.push(res.songinfo)
                    console.log(this.coll);
                });
            }
        },
        methods:{
            changeUrl(i){
                this.$router.push('/musicDetail?songId='+i)
            }
        }
    }
</script>

<style lang="less" scoped>
    .singer-img {
        width: 100%;
        height: 190px;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        position: relative;

        i {
            position: absolute;
            top: 110px;
            left: 48%;
            font-size: 20px;
            z-index: 100;
        }

        img {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            z-index: 100;
            margin-top: 20px;
        }

        p {
            margin: 0;
            padding: 0;
            height: 30px;
            text-align: center;
            width: 100%;
            font-size: 16px;
            margin-bottom: 20px;
        }

        div {
            width: 100%;
            height: 100%;
            opacity: 0.2;
            background-image: url("../assets/img/num11.jpg");
            background-size: 100% 100%;
            position: absolute;
            top: 0;
            left: 0;
        }
    }
    .mysong{
        li{
            padding: 10px 20px;
            border-bottom: 1px solid #eeeeee;
            .mysong-img{
                display: flex;
                justify-content: space-between;
                align-items: center;
                img{
                    width: 50px;
                    height: 50px;
                    border-radius: 50%;
                }
                div{
                    width: calc(100% - 60px);
                }
                div span:nth-of-type(2){
                    font-size: 12px;
                    color: #999999;
                }
            }
        }
    }
</style>